﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TestDemo03
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
        {

        }

        private void mainRectangle_MouseEnter(object sender, MouseEventArgs e)
        {
            //鼠标进入控件，控件颜色为红色

            //mainRectangle.Fill = new SolidColorBrush(Colors.Red);
            mainRectangle.Fill = new SolidColorBrush(Colors.Aqua);
           // MessageBox.Show("进来");
        }

        private void mainRectangle_MouseMove(object sender, MouseEventArgs e)
        {
          
            //获取基于Rectangle 的鼠标的坐标
            ; Point pointBaseRectangle = Mouse.GetPosition(mainRectangle);
            txtMessage.Text = string.Format(
                "Mouse Position (Base the Rectangle) is ({0},{1})",
                pointBaseRectangle.X, pointBaseRectangle.Y
                );
            txtMessage.Text += "\r\n";

            // 获取基于窗体的鼠标的坐标
            Point pointBaseWindow = Mouse.GetPosition(this);
            txtMessage.Text += string.Format(
                 "Mouse Position (Base the Window) is ({0},{1})",
                 pointBaseWindow.X, pointBaseWindow.Y);
        }

        private void mainRectangle_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            if (e.Delta > 0)
                      {
                          // 如果向上推动滚轮，图形的宽度增加
           mainRectangle.Width++;
                     }
               
        if (e.Delta < 0)
                     {
                        // 如果向下推动滚轮，图形的宽度减小
          mainRectangle.Width--;
                  }
        }

        private void mainRectangle_MouseDown(object sender, MouseButtonEventArgs e)
        {
            // 获取点出的鼠标的按钮
            MouseButton button = e.ChangedButton;
            txtMessage.Text += "\r\n";
            txtMessage.Text+=string.Format(
            " Mouse Button is {0}", button.ToString());
        }

        private void mainRectangle_MouseLeave(object sender, MouseEventArgs e)
        {
            //鼠标离开控件，控件颜色为白色
            mainRectangle.Fill = new SolidColorBrush(Colors.White);
            //  MessageBox.Show("出去");
        }
    }
}
